package com.odontosis.view;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.ajaxtags.servlets.BaseAjaxServlet;
import org.ajaxtags.xml.AjaxXmlBuilder;

import com.odontosis.entidade.Paciente;
import com.odontosis.ioc.ContainerIoc;
import com.odontosis.service.PacienteService;

/**
 * Servlet do auto complete
 * 
 * @author Pablo Henrique dos Reis
 * 
 */
public class AutocompleteServlet extends BaseAjaxServlet {

  /**
   * @see BaseAjaxServlet#getXmlContent(javax.servlet.http.HttpServletRequest,
   *      javax.servlet.http.HttpServletResponse)
   */
  public String getXmlContent(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    String model = request.getParameter("model");
    PacienteService service = ContainerIoc.getPacienteService();
    List<Paciente> list = service.pesquisarParaAutoComplete(model);
    
    

    // Create xml schema
    String retorno ="";
    try{
    	 retorno = new AjaxXmlBuilder().addItems(list, "descricaoAutoComplete", "id",true).toString();
    }catch (Exception e) {
    	e.printStackTrace();
	}
    return retorno;
  }

}

